package com.hbmcc.heshenghuo.model.http.bean

import android.text.TextUtils
import android.view.Gravity
import com.google.gson.annotations.SerializedName

/**
 * Copyright (c) 2020
 * 欣网互联网络科技有限公司
 * author: whs
 * created on: 2020/5/11 16:02
 * description:
 */
class TitleAndUrlBean {
    @SerializedName("F_FLOOR_SEAT")
    var floorSeat: String? = null

    @SerializedName("F_MORE_URL")
    var moreUrl: String? = null

    @SerializedName("F_FU_TITLE")
    var fuTitle: String? = null

    @SerializedName("F_NAME")
    var name: String? = null

    @SerializedName("F_IS_CLOSE")
    var isClose: String? = null

    @SerializedName("F_IS_TITLE")
    var isTitle: String? = null

    @SerializedName("F_MORE_NAME")
    var moreName: String? = null
        get() = if (TextUtils.isEmpty(field)) "更多" else field

    @SerializedName("F_BEIJING_URL")
    val beijingUrl: String? = null

    @SerializedName("F_ID")
    var id: String? = null

    @SerializedName("F_SORT")
    var sort = 0
    private var fFloorCode: String? = null
    var hour: String? = null
    var minute: String? = null
    var second: String? = null
    var timerEnd: Long = 0
    var titleType = 0
    var titleIconUrl:String? = null

    fun initTime() {
        val timer = (timerEnd - System.currentTimeMillis() / 1000).toInt()
        if (timer <= 0) {
            hour = "00"
            minute = hour
            second = minute
            return
        }
        val hourTime = timer / HOUR
        hour = if (hourTime < 10) "0$hourTime" else "" + hourTime
        val minueTime = timer % HOUR / MINUTE
        minute = if (minueTime < 10) "0$minueTime" else "" + minueTime
        val secondTime = timer % MINUTE
        second = if (secondTime < 10) "0$secondTime" else "" + secondTime
    }

    fun setTimer(timer: Long) {
        timerEnd = timer
    }

    val isHideTitle: Boolean
        get() = TextUtils.isEmpty(moreUrl)

    fun titleGravity(): Int {
        return if ("1" == floorSeat) Gravity.CENTER_HORIZONTAL else Gravity.CENTER_VERTICAL
    }

    /**
     * 如果居中不展示倒计时
     */
    val isHideTimer: Boolean
        get() = "1" == floorSeat || TextUtils.isEmpty(hour)

    /**
     * 如果居中,显示倒计时 不展示副标题
     */
    val isHideFuTitle: Boolean
        get() = "1" == floorSeat || !TextUtils.isEmpty(hour)

    fun getfFloorCode(): String? {
        return fFloorCode
    }

    fun setfFloorCode(fFloorCode: String?) {
        this.fFloorCode = fFloorCode
    }

    companion object {
        /**
         * F_CITY : 1
         * F_FLOOR_SEAT : 1
         * F_MODEL_NUM : LC-111
         * F_PARAM1 : 1
         * F_PARAM2 : 1
         * F_MORE_URL : http://www.hao123.com
         * F_FU_TITLE :
         * F_SORT : 2
         * F_PLATFORM : 1
         * F_NAME : 宽带家庭
         * F_IS_CLOSE : 1
         * F_LOCATION : 1
         * F_FLOOR_DESC : 宽带家庭奥斯卡的家里开放冷冻室里看电视
         * F_IS_TITLE : 1
         * F_MORE_NAME
         */
        private const val HOUR = 3600
        private const val MINUTE = 60
    }
}